package com.cqut.service.impl;

import com.cqut.VO.discuss.DiscussContentVO;
import com.cqut.entity.Discuss;
import com.cqut.mapper.DiscussMapper;
import com.cqut.service.DiscussService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 冯永龙
 * @since 2021-06-15
 */
@Service
public class DiscussServiceImpl implements DiscussService {

    @Autowired
    private DiscussMapper discussMapper;

    @Override
    public boolean insertDiscuss(Discuss discuss) {
        String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        discuss.setPublicTime(date);
        return discussMapper.insertDiscussContent(discuss) == 1;
    }

    @Override
    public boolean deleteDiscuss(Integer discussId) {
        return discussMapper.deleteDiscussContent(discussId) == 1;
    }

    @Override
    public List<DiscussContentVO> getContentList(Integer topicId) {
        return discussMapper.getContentList(topicId);
    }

    @Override
    public int getTotalContentNumber(Integer topicId) {
        return discussMapper.getTotalContentNumber(topicId);
    }
}
